package com.ceba.test.base.configs;

import java.util.Properties;

import com.ceba.base.config.ServerCommonConfig;
import com.ceba.cebacer.KeyLoaderType;
import com.ceba.cebautils.StringUtil;

public class ServerSignConfig extends ServerCommonConfig{
	//第三方系统对接,上传文档对应url
    public static String thirdUploadFileSystemUrl="";

	// 时间戳服务类型：0-不启用时间戳服务；1-通用时间戳服务；2-上海ca时间戳服务器。默认为1。
	public static int tsaType;
	//时间戳路径
    public static String tsaUrl;
    //时间戳用户名
    public static String tsaUser;
    //时间戳密码
    public static String tsaPsw;
    //是否启用服务器签名走流程
    public static boolean  SERVER_SIGN_FLOW;
    //签名服务器走流程默认 签名根证书
    public static int serverFatherType;
    
    //服务器签名IP地址
    public static String signServerIp = "";
    //服务器签名PORT
    public static String serverSignPort;
    //服务器签名地址后缀
    public static String serverSignSuffix;
    

	public static void configServerSignConfig(Properties prop) {
		signServerIp = prop.getProperty("signServerIp");
		thirdUploadFileSystemUrl = prop.getProperty("thirdUploadFileSystemUrl");
		tsaType = Integer.parseInt(prop.getProperty("tsaType", "0"));
		// 0-不启用时间戳服务；1-通用时间戳服务；2-上海ca时间戳服务器。
		if(0 != tsaType){
			tsaUrl = prop.getProperty("tsaUrl");
			tsaUser = prop.getProperty("tsaUsername");
			tsaPsw = prop.getProperty("tsaPassword");
		}
		//签名服务参数 --信安
		SERVER_SIGN_FLOW = "true".equals(prop.getProperty("serverSignFlow"))?true:false;
		serverFatherType = StringUtil.isEmptyString(prop.getProperty("serverFatherType"))?
				1:Integer.valueOf(prop.getProperty("serverFatherType"));
		serverSignPort =  prop.getProperty("serverSignPort");
		serverSignSuffix =  prop.getProperty("serverSignSuffix");
		ServerCommonConfig.rsaHashType = prop.getProperty("rsaHashType","2");
		thirdUploadFileSystemUrl= StringUtil.removeBlank(thirdUploadFileSystemUrl);
		thirdUploadFileSystemUrl = StringUtil.deleteLastSlash(thirdUploadFileSystemUrl);
		
		initKS(prop);
	}
    
	/**
	 * 凯撒服务器
	 * @param prop
	 */
	public static void initKS(Properties prop) {
			ServerCommonConfig.serverType = prop.getProperty("serverType","2");
			if(!StringUtil.isEmptyString(ServerCommonConfig.serverType)){
				if(KeyLoaderType.TYPE_SERVER_KS == Integer.valueOf(ServerCommonConfig.serverType)){
					ServerCommonConfig.appCode = prop.getProperty("appCode");
					ServerCommonConfig.appPWD = prop.getProperty("appPWD");
				}
			}
		}
}
